package com.atgm.mall.gmmailorder.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建交换机、队列、绑定
 */
@Configuration
public class MyMyConfig {

    /**
     * 容器中的Binding、Queue Exchange  自动创建
     * @return
     */
    @Bean
    public Queue orderDelayQueue() {
        Map<String, Object> param = new HashMap<>();
        param.put("x-dead-letter-exchange", "order-event-exchange");
        param.put("x-dead-letter-routing-key", "order.release.order");
        param.put("x-message-ttl", 60000);
        Queue queue = new Queue("order.delay.queue", true, false, false, param);
        return queue;
    }

    @Bean
    public Queue orderReleaseOrderQueue() {
        return new Queue("order.release.order.queue", true, false, false);
    }

    @Bean
    public Exchange orderEventExchange() {
        return new TopicExchange("order-event-exchange", true, false);
    }

    @Bean
    public Binding orderCreateOrderBinding() {
        return new Binding("order.delay.queue",
                Binding.DestinationType.QUEUE, "order-event-exchange", "order.create.order", null);
    }

    @Bean
    public Binding orderReleaseOrderBinding() {
        return new Binding("order.release.order.queue",
                Binding.DestinationType.QUEUE, "order-event-exchange", "order.release.order", null);
    }

    /**
     * 订单释放直接和库存释放进行绑定
     * @return
     */
//    @Bean
//    public Binding orderReleaseOtherBinding() {
//
//        return new Binding("stock.release.stock.queue",
//                Binding.DestinationType.QUEUE,
//                "order-event-exchange",
//                "order.release.other.#",
//                null);
//    }

    /**
     * 商品秒杀队列
     * @return
     */
//    @Bean
//    public Queue orderSecKillOrrderQueue() {
//        Queue queue = new Queue("order.seckill.order.queue", true, false, false);
//        return queue;
//    }

//    @Bean
//    public Binding orderSecKillOrrderQueueBinding() {
//        Binding binding = new Binding(
//                "order.seckill.order.queue",
//                Binding.DestinationType.QUEUE,
//                "order-event-exchange",
//                "order.seckill.order",
//                null);
//
//        return binding;
//    }

}
